﻿using SuperJoe.Framework.Core.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WWX.Model;

namespace WWX.Admin.Web.Models
{
    public class UserSaveVM
    {
        public string Id { get; set; }

        public string Account { get; set; }

        public string Remark { get; set; }

        public string Pwd { get; set; }

        public bool? IsActive { get; set; }

        public User ToUser()
        {
            if (IsActive == null)
            {
                ThrowHelper.ThrowFriendlyException("请输入状态");
            }

            if (Account.IsNullOrWhiteSpace())
            {
                ThrowHelper.ThrowFriendlyException("请输入账号");
            }

            if (this.Id.IsNullOrWhiteSpace() && this.Pwd.IsNullOrWhiteSpace())
            {
                ThrowHelper.ThrowFriendlyException("请输入密码");
            }

            return new User()
            {
                Id = this.Id,
                Account = this.Account,
                Remark = this.Remark,
                IsActive = this.IsActive.Value,
                Pwd = this.Pwd
            };
        }
    }
}